package com.foreknow.view;

import com.foreknow.bean.Guestbook;
import com.foreknow.service.impl.GuestbookServiceImpl;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Update extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Update frame = new Update();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Update() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		panel.setBorder(new EmptyBorder(5, 5, 5, 5));
		panel.setBounds(0, 10, 434, 261);
		contentPane.add(panel);
		
		JLabel label = new JLabel("name");
		label.setBounds(33, 10, 54, 15);
		panel.add(label);
		
		textField = new JTextField();
		textField.setColumns(10);
		textField.setBounds(95, 7, 66, 21);
		panel.add(textField);
		
		JLabel label_1 = new JLabel("phone");
		label_1.setBounds(33, 62, 54, 15);
		panel.add(label_1);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(95, 59, 66, 21);
		panel.add(textField_1);
		
		JLabel label_2 = new JLabel("email");
		label_2.setBounds(33, 111, 54, 15);
		panel.add(label_2);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(95, 108, 66, 21);
		panel.add(textField_2);
		
		JLabel label_3 = new JLabel("title");
		label_3.setBounds(218, 10, 54, 15);
		panel.add(label_3);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setBounds(282, 7, 66, 21);
		panel.add(textField_3);
		
		JLabel label_4 = new JLabel("content");
		label_4.setBounds(218, 65, 54, 15);
		panel.add(label_4);
		
		textField_4 = new JTextField();
		textField_4.setColumns(10);
		textField_4.setBounds(282, 59, 66, 21);
		panel.add(textField_4);
		
		JLabel label_5 = new JLabel("createdtime");
		label_5.setBounds(196, 111, 76, 15);
		panel.add(label_5);
		
		textField_5 = new JTextField();
		textField_5.setColumns(10);
		textField_5.setBounds(282, 108, 66, 21);
		panel.add(textField_5);
		
		JButton button = new JButton("\u786E\u8BA4\u4FEE\u6539");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				GuestbookServiceImpl guestbookService = new GuestbookServiceImpl();
				int id = Integer.parseInt(textField_6.getText());
//				Guestbook g = guestbookService.query(id);
//				textField.setText(g.getName());
//				textField_1.setText(g.getPhone());
//				textField_2.setText(g.getEmail());
//				textField_3.setText(g.getTitle());
//				textField_4.setText(g.getContent());
//				textField_5.setText(g.getCreatedtime());
				//-----------------------------------------------------
				String name = textField.getText();
				String phone = textField_1.getText();
				String email = textField_2.getText();
				String title = textField_3.getText();
				String content = textField_4.getText();
				String createdtim = textField_5.getText();
				int a = guestbookService.update(id,name,phone,email,title,content,createdtim);
				System.out.println(a);
			}
		});
		button.setBounds(123, 184, 173, 40);
		panel.add(button);
		
		JLabel lblid = new JLabel("\u4FEE\u6539\u7684id");
		lblid.setBounds(123, 154, 54, 15);
		panel.add(lblid);
		
		textField_6 = new JTextField();
		textField_6.setBounds(187, 153, 66, 21);
		panel.add(textField_6);
		textField_6.setColumns(10);
		this.setVisible(true);
	}
}
